package com.huawei.appgallery.forum.user.menu;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
import java.math.BigDecimal;
import o.azb;
import o.cbb.a;
import o.cbb.b;
import o.cbb.c;
import o.cbb.d;
import o.cbb.e;
import o.cgv;
import o.epo;
import o.epv;
import o.erq;

public class UserActionBar extends LinearLayout implements OnClickListener {
    private int ʻ;
    private int ʼ;
    private int ʽ;
    private MenuLinearLayout ˊ;
    private Window ˊॱ;
    private ImageView ˋ;
    private Drawable ˎ;
    private TextView ˏ;
    private int ॱ;
    private int ॱˊ;
    private int ॱॱ;
    private int ᐝ;

    public UserActionBar(Context context) {
        this(context, null);
    }

    public UserActionBar(Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public UserActionBar(Context context, @Nullable AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        ˎ(context);
        this.ॱ = context.getResources().getColor(c.ᐝ);
    }

    private void ˎ(Context context) {
        View findViewById = View.inflate(context, d.ʻ, null).findViewById(b.ʼˊ);
        azb.ˏ(findViewById);
        findViewById.setOnClickListener(this);
        ((RelativeLayout) findViewById.findViewById(b.ʼ)).setOnClickListener(this);
        this.ˋ = (ImageView) findViewById.findViewById(b.ᐝˋ);
        this.ˎ = context.getResources().getDrawable(a.ˏ);
        View findViewById2 = findViewById.findViewById(b.ʼˋ);
        if (VERSION.SDK_INT >= 21) {
            findViewById2.setLayoutParams(new LayoutParams(-1, epv.ˋ(context)));
            findViewById2.setVisibility(0);
        } else {
            findViewById2.setVisibility(8);
        }
        this.ˏ = (TextView) findViewById.findViewById(b.ʽˋ);
        this.ˊ = (MenuLinearLayout) findViewById.findViewById(b.ꜟ);
        addView(findViewById, new LayoutParams(-1, -2));
        int ˏ = ˏ(context);
        this.ʻ = context.getResources().getDimensionPixelSize(e.ॱˊ) + ˏ;
        this.ॱॱ = context.getResources().getDimensionPixelSize(e.ˏॱ) + ˏ;
        this.ʼ = context.getResources().getDimensionPixelSize(e.ᐝ);
        this.ᐝ = ˏ + context.getResources().getDimensionPixelSize(e.ˊॱ);
        this.ॱˊ = context.getResources().getDimensionPixelSize(e.ˊॱ);
        if (VERSION.SDK_INT >= 21) {
            this.ˊॱ = ((Activity) getContext()).getWindow();
        }
    }

    public void setTitle(String str) {
        this.ˏ.setText(str);
    }

    public MenuLinearLayout ˏ() {
        return this.ˊ;
    }

    public void ˏ(int i, int i2) {
        int i3 = i2 - this.ʻ;
        int i4 = i2 - this.ॱॱ;
        this.ʽ = i2 - this.ᐝ;
        if (i < i3) {
            ˋ(-1, 1.0f);
            this.ˏ.setAlpha(0.0f);
            ˎ(0.0f);
            ˏ(-16777216);
        } else if (i <= i4) {
            ˋ(-1, new BigDecimal(1.0d).subtract(new BigDecimal(i - i3).divide(new BigDecimal(this.ʼ), 3, 0)).floatValue());
            this.ˏ.setAlpha(0.0f);
            ˎ(0.0f);
            ˏ(-16777216);
        } else if (i <= this.ʽ) {
            ˋ(-1, 0.0f);
            this.ˏ.setAlpha(0.0f);
            ˎ(0.0f);
            ˏ(-16777216);
        } else {
            float ॱ = ॱ(i, i2);
            ˋ(getResources().getColor(c.ˎ), ॱ);
            this.ˏ.setAlpha(ॱ);
            ˎ(ॱ);
            ˏ(getResources().getColor(c.ʼ));
        }
    }

    private void ˏ(int i) {
        if (this.ˊॱ == null) {
            return;
        }
        if (!cgv.ˎ()) {
            this.ˊॱ.setStatusBarColor(i);
        } else if (erq.ˏ(i)) {
            cgv.ˏ(this.ˊॱ, 1);
        } else {
            cgv.ˏ(this.ˊॱ, 0);
        }
    }

    private void ˋ(int i, float f) {
        int ˊ = erq.ˊ(i, f);
        for (MenuLinearLayout.e eVar : this.ˊ.ˋ()) {
            eVar.ॱ().setBackground(epo.ॱ(eVar.ˊ(), ˊ));
        }
        this.ˋ.setBackground(epo.ॱ(this.ˎ, ˊ));
    }

    private void ˎ(float f) {
        setBackgroundColor(erq.ˊ(this.ॱ, f));
    }

    private float ॱ(int i, int i2) {
        if (i2 <= 0 || i - this.ʽ == 0) {
            return 1.0f;
        }
        float floatValue = new BigDecimal(1.0d).divide(new BigDecimal(this.ॱˊ), 3, 0).floatValue() * ((float) (i - this.ʽ));
        if (floatValue <= 1.0f) {
            return floatValue;
        }
        return 1.0f;
    }

    private int ˏ(Context context) {
        int dimensionPixelSize = getContext().getResources().getDimensionPixelSize(e.ʻ);
        if (VERSION.SDK_INT >= 21) {
            return dimensionPixelSize + epv.ˋ(context);
        }
        return dimensionPixelSize;
    }

    public void onClick(View view) {
        if (view.getId() == b.ʼ) {
            Context context = getContext();
            if (context instanceof Activity) {
                ((Activity) context).finish();
            }
        }
    }
}
